import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'resultId',
    label: '结果ID',
  },
  {
    component: 'Input',
    fieldName: 'auditItemId',
    label: '审核项目ID',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.AUDIT_RESULT 便于维护
      options: getDictOptions('audit_result'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    fieldName: 'auditItemResult',
    label: '审核项目结果',
  },
  {
    component: 'Textarea',
    fieldName: 'auditAdvice',
    label: '审核建议',
  },
  {
    component: 'Input',
    fieldName: 'auditHumanResult',
    label: '人工审核结果',
  },
  {
    component: 'Textarea',
    fieldName: 'auditHumanAdvice',
    label: '人工审核建议',
  },
  {
    component: 'Input',
    fieldName: 'auditUser',
    label: '人工审核人',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '明细ID',
    field: 'detailId',
  },
  {
    title: '结果ID',
    field: 'resultId',
  },
  {
    title: '审核项目ID',
    field: 'auditItemId',
  },
  {
    title: '审核项目结果',
    field: 'auditItemResult',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.AUDIT_RESULT 便于维护
        return renderDict(row.auditItemResult, 'audit_result');
      },
    },
  },
  {
    title: '审核建议',
    field: 'auditAdvice',
  },
  {
    title: '人工审核结果',
    field: 'auditHumanResult',
  },
  {
    title: '人工审核建议',
    field: 'auditHumanAdvice',
  },
  {
    title: '人工审核人',
    field: 'auditUser',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const modalSchema: FormSchemaGetter = () => [
  {
    label: '明细ID',
    fieldName: 'detailId',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '结果ID',
    fieldName: 'resultId',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '审核项目ID',
    fieldName: 'auditItemId',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '审核项目结果',
    fieldName: 'auditItemResult',
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.AUDIT_RESULT 便于维护
      options: getDictOptions('audit_result'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
  {
    label: '审核建议',
    fieldName: 'auditAdvice',
    component: 'Textarea',
    rules: 'required',
  },
  {
    label: '人工审核结果',
    fieldName: 'auditHumanResult',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '人工审核建议',
    fieldName: 'auditHumanAdvice',
    component: 'Textarea',
    rules: 'required',
  },
  {
    label: '人工审核人',
    fieldName: 'auditUser',
    component: 'Input',
    rules: 'required',
  },
];
